package edu.tsinghua.ddb.sandbox;

import java.io.FileNotFoundException;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import edu.tsinghua.ddb.main.Interpreter;


public class ScriptRunner {
	public static void main(String[] args) {
		Interpreter.runScript(".createTable(\"new table\",[])");
		Interpreter.runScript(".createTable(\"new table\",45)");
//		runScriptFile("conf/init.js");
	}

	public static void runScriptFile(String filePath) {
		// create a script engine manager
		ScriptEngineManager factory = new ScriptEngineManager();
		// create JavaScript engine
		ScriptEngine engine = factory.getEngineByName("JavaScript");
		// evaluate JavaScript code from given file - specified by first
		// argument
		try {
			engine.eval(new java.io.FileReader(filePath));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ScriptException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void evalSafely(String script){
//		engine.eval(script);
	}
}
